package com.newbie.cellsms.base;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 封装对sqlite的操作
 * 
 * @author Jacarri
 * 
 */
public class SQLiteUtil {

	private static String dbFolder = "jdbc:sqlite:/etc/OpenBTS/";

	private static Connection geStatement(String dbFileName) throws ClassNotFoundException, SQLException {
		// 如果系统不是linux
		if (!File.separator.endsWith("/")) {
			dbFolder = "jdbc:sqlite:D:/portal2_project/cellsmsweb/OpenBTS/";
		}
		Class.forName("org.sqlite.JDBC");
		Connection connection = null;
		connection = DriverManager.getConnection(dbFolder + dbFileName + ".db");
		// Statement statement = connection.createStatement();
		// statement.setQueryTimeout(30);
		return connection;
	}

	public static Connection getOpenBTSConnection() throws ClassNotFoundException, SQLException {
		return geStatement("OpenBTS");
	}

	public static Connection getSmqBackupConnection() throws ClassNotFoundException, SQLException {
		return geStatement("smq.backup");
	}

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		System.out.println(SQLiteUtil.getOpenBTSConnection());
		System.out.println(SQLiteUtil.getSmqBackupConnection());
	}
}
